package com.jhgsys.internal.common.controller.app;

import com.jhgsys.internal.common.constant.FileUploadConstant;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.utils.ImageUtils;
import com.jhgsys.internal.common.utils.UploadPathUtil;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@RestController()
@RequestMapping("app/common")
public class AppCommonUploadController extends BaseController {

    /**
     * 文件上传
     * @param imgBase64Str
     * @return
     */
    @PostMapping(value = "upload")
    @ResponseBody
    public FebsResponse uploadSignature(@RequestBody String imgBase64Str) {
        try {
            String filePath = FileUploadConstant.SIGNATURE_FILE_PATH + '/';
            String path = UploadPathUtil.getRootPath() + filePath;
            String fileName = ImageUtils.GenerateImage(imgBase64Str, path);
//            return new FebsResponse().success().data(filePath + fileName);
            return new FebsResponse().success().data("files/"+ FileUploadConstant.SIGNATURE_FILE_PATH+"/"+fileName);
        } catch (Exception ex) {
            return new FebsResponse().fail().message("文件流上传失败");
        }
    }
}
